﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BitPortal.Business;
using BitPortal.Models;

namespace BitPortal.Modules.VerticalMenu
{
    public partial class VerticalMenu : Controls.BaseUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void BindMenu(Models.Menu item)
        {
            if (item.GetChilds().Count > 0)
            {
                ltrMenu.Text += "<li><span><a href=\"javascript:void(0)\" >" + item.Name + "</a></span>";
                ltrMenu.Text += "<ul>";
                foreach (Models.Menu child in item.GetChilds())
                {
                    BindMenu(child);
                }
                ltrMenu.Text += "</ul>";
            }
            else
            {
                ltrMenu.Text += "<li><span><a href=\"" + item.TargetUrl + "\" target=\"" + item.Target + "\">" + item.Name + "</a></span>";
            }
            ltrMenu.Text += "</li>";
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            ltrTitle.Text = ReferenceModule.GetModuleConfig("Header").ToString();
            ltrMenu.Text = "";
            foreach (Models.Menu item in MenuBLL.GetAll(position: 1).Where(ent => ent.ParentID == null))
            {
                BindMenu(item);
            }
        }
    }
}